package ar.edu.itba.it.pdc.httpParser;

import ar.edu.itba.it.pdc.httpParser.interfaces.Parser;
import ar.edu.itba.it.pdc.httpParser.models.HttpBody;
import ar.edu.itba.it.pdc.httpParser.models.Token;

public class LengthBodyParser implements Parser {

	private int contentLength;
	private int lengthCount;

	private HttpBody model = new HttpBody();

	public LengthBodyParser(int contentLength) {
		this.contentLength = contentLength;
	}

	@Override
	public int parseToken(Token token) {

		lengthCount += token.length();
		model.append(token);

		return  contentLength - lengthCount;
	}

	@Override
	public HttpBody getModel() {
		return model;
	}

}